

export const checkID = (code) => {
    var regx = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
    return regx.test(code)
};

export const checkPhone = (val) => {
    return /^1[3456789]\d{9}$/.test(val);
}

export const blobToBase64 = (blob, cb) => {
    let reader = new FileReader();
    reader.onload = function (evt) {
        let base64 = evt.target.result;
        cb(base64);
    };
    reader.readAsDataURL(blob);
};

export const IdCardInfo = (UUserCard, num) => {
    if (num == 1) {
        //获取出生日期
        let birth = UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
        return birth;
    }
    if (num == 2) {
        //获取性别
        if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
            //男
            return "男";
        } else {
            //女
            return "女";
        }
    }
    if (num == 3) {
        //获取年龄
        var myDate = new Date();
        var month = myDate.getMonth() + 1;
        var day = myDate.getDate();
        var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
        if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
            age++;
        }
        return age;
    }
}
export const regexPlate = (plate) => {

    if (plate.length > 9) {
        return false
    }
    // 常规车牌和新能源车牌
    let plateRegex = /((^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领军][A-Za-z](([0-9]{5}[A-Za-z])|([A-Za-z]([A-HJ-NP-Za-hj-np-z0-9])[0-9]{4})))|(^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领军空海北沈兰济南广成临][A-Za-z][A-HJ-NP-Za-hj-np-z0-9]{4}[A-HJ-NP-Za-hj-np-z0-9挂学警港澳使领]))$/i;

    // 军用车牌
    let regular = /^[A-Z]{2}[0-9]{5}$/i;
    // 武警车牌
    let wjRegex = /^WJ[京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云渝藏陕甘青宁新]?[0-9a-zA-Z]{5}$/i
    let wjRegex2 = /^(WJ)[0-9]{2}(消|边|通|森|金|警|电|[a-zA-Z0-9])[a-zA-Z0-9]{4}$/i


    if (plateRegex.test(plate) | regular.test(plate) | wjRegex.test(plate) | wjRegex2.test(plate)) {
        return true;
    } else {
        return false;
    }
}